<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Victor
 * Date: 08.12.11
 * Time: 14:06
 * To change this template use File | Settings | File Templates.
 */

class profileController extends Core_BaseController
{

    function indexAction($profileName = -1)
    {
        // TODO: Implement indexAction() method.
        $permission = array('user', 'admin', 'moderator');
        $this->twig = $this->getRegistry()->twig;
        $allow = $this->userHasPermission($permission);
        if ($allow) {
            $auth = $this->checkAuth();
            $userManager = new User_Manager();
            $userInfo = $userManager->getUserInformation($auth);

            if(!$userInfo){
              $err = array('err' =>"Такого профиля не существует");
              $data = array_merge($err, $auth);


                $template = $this->twig->loadTemplate('profile_index.html.twig');
            $template->display($data);

            }else{
                $role = $this->getAuth()->getUserRoles($auth);
                 $lessonManager = new Lesson_Lesson();
                $lessonMarks = $lessonManager->getUserLessonMarks($auth['name']);
                // $this->vardump("Lesson marks",$lessonMarks);

            $data = array_merge(array('user' => $userInfo, 'role' => $role,'lessonmarks'=>$lessonMarks), $auth);
               // $this->vardump("",$data);
            $template = $this->twig->loadTemplate('profile_index.html.twig');
            $template->display($data);
            }

        } else {
             $template = $this->twig->loadTemplate('access.html.twig');
            echo $template->render(array());
        }
    }
}
